package cn.itcast.nems.manager.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * author liyong
 * create: 2024-04-10 11:23:27
 **/
public final class WeixinMessageUtil {
    private static final Logger logger = LoggerFactory.getLogger(WeixinMessageUtil.class);

    public static String createWeixinMessage(String journalId,
                                             String journalType,
                                             String bpmBizKey,
                                             String msgId,
                                             String userName,
                                             String userEmail,
                                             String envProfile,
                                             Exception e) {
        return "凭单类型：" + journalType + "\n" + "凭单ID：" + journalId + "\n" +
                "审批单ID：" + bpmBizKey + "\n" +
                "凭单发起人：" + userName + "(" + userEmail + ")\n" +
                "消息ID：" + msgId + "\n" +
                "消息来自：" + getHostIp() + "\n" +
                "问题描述：" + "审批单完成处理失败(" + envProfile + ")\n" +
                "错误原因：" + e.getMessage();
    }

    private static String getHostIp() {
        String ipAddress = "Unknown";
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            ipAddress = localHost.getHostAddress();
        } catch (UnknownHostException e) {
            logger.warn(e.getMessage(), e);
        }
        return ipAddress;
    }
}
